/*
 * 
 * 
 */

/*
 * JDialogPlik.java
 *
 * Created on 2009-08-10, 20:25:39
 */

package steg.gui.steg;

import java.awt.Frame;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker.StateValue;
import steg.steki.PlikSteg;
import steg.steki.StegException;
import steg.sekret.Sekret;
import steg.utils.MojaLinkedHashMap;

/**
 *
 * @author Tryllion
 */
public abstract class JDialogPlik extends javax.swing.JDialog {

    protected static String PATH_LST_OPEN = "C:\\BUCKUP\\Teraz\\SVN\\plikiTestowe\\"; // ostatnio otwarta scierzka w JFileChooser
    protected static final String PLIK_STEG_EXTENCION = ".steg.";
    protected static final int ERROR_STEG_PLIK = 0;
    protected static final int ERROR_SEKRET_PLIK = 1;
    protected static final int ERROR_INNY = 1;

    // stegi
    protected Sekret sekret; //pusty kontener na sekret
    protected PlikSteg plikStegowany;

    private boolean isPlikStegowany = false;
    private boolean isPlikSekret = false;



    /** Creates new form JStegStart */
    public JDialogPlik(Frame owner, String title, boolean modal){
        super(owner, title, modal);
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        jCheckBox3 = new javax.swing.JCheckBox();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jProgressBar2 = new javax.swing.JProgressBar();
        jButtonStart = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 24));
        jLabel1.setForeground(new java.awt.Color(68, 30, 30));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("XXX steganografia");

        jPanel1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jPanel1PropertyChange(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jRadioButton1.setText("tekst");
        jRadioButton1.setToolTipText("tekst/plik");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/massage.png"))); // NOI18N
        jButton1.setToolTipText("wczytaj wiadomość");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/massage.png"))); // NOI18N
        jButton2.setToolTipText("wczytaj plik steganograficzny");
        jButton2.setMargin(new java.awt.Insets(2, 1, 2, 1));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("...");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("GZIP");
        jCheckBox1.setToolTipText("wiadomośc zostanie skompresowana");

        jCheckBox2.setText("haslo");
        jCheckBox2.setToolTipText("hasło programu, nie pliku GZIP");
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jPasswordField1.setEditable(false);

        jCheckBox3.setSelected(true);
        jCheckBox3.setText("tag");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8", "4", "2", "1" }));

        jLabel3.setText("Bitów na bajt");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox2)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap(355, Short.MAX_VALUE))
        );

        jProgressBar2.setMaximum(1000);

        jButtonStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/start.png"))); // NOI18N
        jButtonStart.setToolTipText("rozpocznij");
        jButtonStart.setEnabled(false);
        jButtonStart.setMargin(new java.awt.Insets(2, 4, 2, 4));
        jButtonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jProgressBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonStart)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jProgressBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
        if(!jRadioButton1.isSelected()) {

            jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/massage.png")));

        }else{
            jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/text.png")));

        }
}//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        isPlikSekret = true; // na error trzeba wygasic

        if(!jRadioButton1.isSelected())
            loadSekretFile();
        else
            loadSekretText();

        czyMOznaGo();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        //pusty model
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {}
        },
                new String [] {

        }
        ));

        isPlikStegowany = true; // na error trzeba wygasic
        loadStegPlik();

        czyMOznaGo();
}//GEN-LAST:event_jButton2ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
        jPasswordField1.setEditable(jCheckBox2.isSelected() );
}//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed

        //zablokowac i ustawic na 0 all
        this.setEnabled(false);
        jProgressBar2.setValue(0);

        // przypisać śledzący aparat :D
        plikStegowany.addComponentWithChangeListener( jPanel1 );
        plikStegowany.setMaxProgressValue( jProgressBar2.getMaximum() );

        // nazwa pliku, dziala to tak cos.exe ->> cos.PLIK_STEG_EXTENCION.exe
        String nazwa = plikStegowany.getFile().getAbsolutePath();
        if(nazwa.indexOf(".")==-1)nazwa += ".steg"; // jkesli ni ma roszerzenia, bo durny error bedzie
        String[] nazwaT = nazwa.split("\\.");
        nazwa = (nazwaT[nazwaT.length-2] + PLIK_STEG_EXTENCION + nazwaT[nazwaT.length-1]);

        steganuj(nazwa);
    }//GEN-LAST:event_jButtonStartActionPerformed

    private void jPanel1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jPanel1PropertyChange

        // ustaw progres
        if ("progress".equals(evt.getPropertyName()))
            jProgressBar2.setValue( (Integer) evt.getNewValue());


        // KONIEC
        if (evt.getNewValue() == StateValue.DONE  ) {

            // czy były błedy ?
            StegException sex= plikStegowany.throwException();
            if(sex!=null) {
                raportError(sex,ERROR_INNY,"błąd steganografii BMP");
                JOptionPane.showMessageDialog(this, sex.getStegMassage(),"Błąd steganograficzny",
                        JOptionPane.ERROR_MESSAGE);
                JOptionPane.showMessageDialog(this, "Proces nie został zakończony.\nProszę zmienić parametry i spróbować ponownie.","Uwaga!",
                        JOptionPane.WARNING_MESSAGE);
                jProgressBar2.setValue( jProgressBar2.getMaximum() );

            }else{
                Toolkit.getDefaultToolkit().beep(); // DZWIEK :D
                JOptionPane.showMessageDialog(this, "Proces został zakończony","Koniec.",
                        JOptionPane.INFORMATION_MESSAGE);
            }
            try {
                //odblokuj
                sekret.close();
            } catch (IOException ex) {
                raportError(ex,ERROR_INNY,"błąd zamkniecia strumienia Sekret");
                JOptionPane.showMessageDialog(this, "Błąd zamknięcia pliku.","Błąd!",
                        JOptionPane.ERROR_MESSAGE);
            }
            zakoncz(); // ostatnie sprawy
            jButtonStart.setEnabled(false);
            this.setEnabled(true);


        }
}//GEN-LAST:event_jPanel1PropertyChange

    private void czyMOznaGo() {
        if(!isPlikStegowany) {jButtonStart.setEnabled(false); return;}
        if(!isPlikSekret) {jButtonStart.setEnabled(false); return;}

        jProgressBar2.setValue(0);
        jButtonStart.setEnabled(true);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonStart;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JProgressBar jProgressBar2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables


    /**
     * Ładuje plik Sekret.
     */
    protected void loadSekretFile() {

        JFileChooser chooser = new JFileChooser();

        chooser.setCurrentDirectory( new File(PATH_LST_OPEN) );

        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {

            try {
                PATH_LST_OPEN = chooser.getSelectedFile().getPath();

                    // 1 tworzymy Sekret
                // czy nie za dugi
                File file = new File(PATH_LST_OPEN);
                if(file.length()>=Long.MAX_VALUE) {
                    // tos ie wogule moze zdarzyc ???
                    JOptionPane.showMessageDialog(this,  "Proszę wybrać krótszą wiadomość.","Plik jest za długi!",
                                        JOptionPane.INFORMATION_MESSAGE);
                    return;
                }

                // ladujemy
                sekret = new Sekret(); // nowy robię a co !
                sekret.setFile(file);
                setNazwaSekretu(sekret.getFile().getName() );


            } catch (Exception ex) {
                raportError(ex,ERROR_SEKRET_PLIK,"Pliku nie udało się wczytać.\n Plik("+PATH_LST_OPEN+")");
                JOptionPane.showMessageDialog(this, "Pliku nie udało się wczytać.\n Plik("+PATH_LST_OPEN+")", "Błąd!",
                    JOptionPane.ERROR_MESSAGE);

            }

        }

    }

    /**
     * Ładuje wiadomość tekstową do Sekret.
     */
    protected void loadSekretText() {

        JDialogTextInput jdti = new JDialogTextInput(this, true);
        jdti.setVisible(true);

        String wiadomosc = jdti.getTextMag();
        try {
            sekret = new Sekret();
            sekret.setWiadomosc(wiadomosc);
            setNazwaSekretu(wiadomosc);
        } catch (IOException ex) {

            JOptionPane.showMessageDialog(this, "Błąd wczytu informacji!", "Przy próbie skompresowania wiadomości nastąpił błąd.",
                    JOptionPane.ERROR_MESSAGE);
            raportError(ex,ERROR_SEKRET_PLIK,"GZIP nieudany!");
        }
    }


    /**
     * Wstawia dane do estetycznej tabelki.
     * @param metaDane
     */
    protected void setMetaDane(MojaLinkedHashMap metaDane) {

        jTable1.setModel(metaDane.getDefaultTableModel());

    }

    /**
     *
     * @param metaDane
     */
    protected void setNazwaSekretu( String nazwa ) {
        if(nazwa.length()>70) nazwa = nazwa.substring(nazwa.length()-70, nazwa.length()); // co by nie byla za dluga
        jLabel2.setText(nazwa);

    }

    /**
     * Raportuje o błędach.
     * @param ex
     */
    protected void raportError(Exception ex,int flag, String opis) {

        // aby wszystko bylo w jednym miejscu, blad takze tu obslugujemy
        /**
         * MYślę że to dobry pomysł, bo różne błedy trzeba będzie różnie obsłużyć
         * Na razie mam 2, więc wydaje się to nie potrzebne, ale cholera wie jak to
         * będzie w przyszłości, zostawiam taki dziwny mechanizm
         *
         */
        if(flag==ERROR_SEKRET_PLIK) isPlikSekret = false;
        if(flag==ERROR_STEG_PLIK) isPlikStegowany = false;

        System.out.println("------------- Raport o błędzie:\n"+opis);
        Logger.getLogger(JDialogPlik.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*opcje opcji , ustawianie czy sa dostepne, nie selected i takie tam !!!!*/
    protected void setIsGZIP(boolean v, boolean b, boolean set) {
        jCheckBox1.setVisible(v);
        jCheckBox1.setEnabled(b);
        jCheckBox1.setSelected(set);
    }
    protected void setIsHaslo(boolean v, boolean b, boolean set) {
        jCheckBox2.setVisible(v);
        jPasswordField1.setVisible(v);
        jCheckBox2.setEnabled(b);
        jPasswordField1.setEnabled(b);
        jCheckBox2.setSelected(set);

    }
    protected void setIsTag(boolean v, boolean b, boolean set) {
        jCheckBox3.setVisible(v);
        jCheckBox3.setEnabled(b);
        jCheckBox3.setSelected(set);
    }


    protected boolean czyText() {
        return jRadioButton1.isSelected();
    }
    protected boolean czyGZIP() {
        return jCheckBox1.isSelected();
    }
    protected boolean czyHaslo() {
        return jCheckBox2.isSelected();
    }
    protected boolean czyTag() {
        return jCheckBox3.isSelected();
    }
    protected char[] getHaslo() {
        return jPasswordField1.getPassword();
    }
    protected int getBitowNaSample() {
        return Integer.parseInt( (String) jComboBox1.getSelectedItem());
    }



    /* czemu init? bardziej dlatego są tak ponazywane i podzielone aby pamietac nizby jakis z tego mial byc uzytek*/
    /**
     * Tytuł nagłówka jak i całej ramki.
     * @param str
     */
    protected void initTilte(String str) {
        this.setTitle(str);
        jLabel1.setText(str);
    }
    protected void initPlikIcon(String str) {
        try{
            jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zimg/"+str)));
        }catch(NullPointerException ex) {
            raportError(ex,ERROR_INNY,"brak pliku->"+str);
        }
    }

    protected abstract void initStartOpcje();

    /*konkrety różne dla każdego rodzaju steganografi*/
    protected abstract void loadStegPlik();
    protected abstract void steganuj(String nazwa);
    protected abstract void zakoncz();


}
